package com.liangzhong.model.helper
{
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.manager.ResourceManager;
	
	import flash.utils.Dictionary;

	public class HelperDateManger
	{
		private var _dic:Dictionary;
		public function HelperDateManger()
		{
		}
		/**
		 *解析数据 
		 * 
		 */
		public function analysisDate():void
		{
			if(_dic != null)return;
			_dic = new Dictionary();
			var startxml:XML = ResourceManager.instance.getResource(ResourceConst.HELPER_XML_RESOURCE);
			var list:XMLList = startxml.children();
			var len:int = list.length();
			var vo:Helpervo;
			for(var i:int = 0;i < len;i++)
			{
				vo = new Helpervo();
				vo.analysisDate(list[i]);
				_dic[vo.id] = vo;
			}
			
			
			
		}
		/**
		 *通过ID获得VO 
		 * @param $id
		 * @return 
		 * 
		 */
		public function getVoById($id:int):Helpervo
		{
			return _dic[$id];
		}
		/**
		 * 通过type page获得VO 
		 * @param $type
		 * @param $page
		 * @return 
		 * 
		 */
		public function getVoByTypeAndPage($type:int,$page:int):Helpervo
		{
			for each(var vo:Helpervo  in _dic)
			{
				if(vo.type == $type && vo.page == $page)
					return vo;
			}
			return null;
		}
		public function getTypeDate($type:int):Array
		{
			var arr:Array = [];
			for each(var vo:Helpervo  in _dic)
			{
				if(vo.type == $type)
					arr.push({name:vo.des,value:vo.page,hostName:vo.hostName});
			}
			arr.sort(sortOn);
			function sortOn(a:Object,b:Object):Number
			{
				if(a.value > b.value)return 1;
				if(a.value < b.value)return -1;
				return 0;
				
			}
			return arr;
		}
	}
}